const app = getApp();
const companyName = app.globalData.companyName;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    club: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getClub();
  },
  getClub: function() {
    wx.showNavigationBarLoading();
    const url = app.globalData.url;
    const that = this
    wx.request({
      url: url + '/management/getClub',
      data: {
        companyName
      },
      method: 'POST',
      success: function(response) {
        wx.stopPullDownRefresh();
        wx.hideNavigationBarLoading();
        if (response.data.success) {
          that.setData({
            club: response.data.content
          });
        } else {
          wx.showToast({
            title: response.data.message,
            icon: 'none'
          })
        }
      }
    })
  },

  onPullDownRefresh: function() {
    this.getClub();
  },
  toBook: function() {
    wx.navigateTo({
      url: '/pages/appointment/appointment'
    })
  },
  changePhone: function () {
    wx.setStorageSync('phone', this.data.club.phone || '');
    wx.navigateTo({
      url: '/pages/changeCompanyPhone/changeCompanyPhone'
    })
  },
  changeAddress:function(){
    wx.setStorageSync('address', this.data.club.address || '');
    wx.navigateTo({
      url: '/pages/changeCompanyAddress/changeCompanyAddress'
    })
  },
  companyPicture:function(){
    wx.setStorageSync('clubPictures', JSON.stringify(this.data.club.clubPictures || []));
    wx.navigateTo({
      url: '/pages/clubPicture/clubPicture'
    })
  },
  emsPicture: function () {
    wx.setStorageSync('trainPictures', JSON.stringify(this.data.club.trainPictures || []));
    wx.navigateTo({
      url: '/pages/emsPicture/emsPicture'
    })
  }
})